#include <glut_render.hpp>
#include <osc-control.hpp>
#include <iostream>
#include <string>

using namespace std;

int
main (int argc, char **argv)
{
  try
  {

//===================================================
    cout << "Connecting to Oscilloscope: " << endl;
    osc_control Agilent_DSO90k;
    cout << "OK" << endl;

//===================================================
    cout << "Test if oscilloscope is ready: " << endl;
    if (!Agilent_DSO90k.testReady ())
      throw "Oscilloscpe is not ready.";
    cout << "OK" << endl;

//===================================================
    cout << "Preset the waveform data format: " << endl;
    if (!Agilent_DSO90k.preset ())
      throw "Cannot preset oscilloscpe.";
    cout << "OK" << endl;

//===================================================
    cout << "Estimate bitmap size: ";
    unsigned long width = Agilent_DSO90k.number_of_points ();
    unsigned long height = (width < 600) ? width : 600;
    cout << '(' << width << ',' << height << ") OK" << endl;

//===================================================
    cout << "Begin acquistion... ";
    glut_render newWindow (argc, argv, width, height, &Agilent_DSO90k);

    char title[] = "osc-radar";
    newWindow.open (title);
    cout << "OK" << endl;

  }
  catch (const char *e)
  {
    cerr << "\nError: " << e << endl;
  }
  catch (string e)
  {
    cerr << "\nError: " << e << endl;
  }
  cout << "Turning off..." << endl;
  return 0;
}
